<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .div {
            width: 250px;
            display: flex;
            margin: 0 auto;
        }
        .div div {
            width: 30px;
            height: 20px;
            background-color: antiquewhite;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            margin: 0 10px;
        }
    </style>
</head>

<body>
    <div class="div">
        <div>胡歌</div>
        <div>彭于晏</div>
        <div>赵玉真</div>
        <div>韩立</div>
        <div>百里东君</div>
    </div>
    <script>
        var div = document.querySelector('.div')
        var divs = div.children
        for (let index = 0; index < divs.length; index++) {
            divs[index].addEventListener('click', function (e) {
                for (let index = 0; index < divs.length; index++) {
                    divs[index].style.backgroundColor = ''
                }
                this.style.backgroundColor = 'red'
            })
        }
    </script>
</body>
</html>